package com.longyue.ms.app.web;

import com.longyue.ms.app.entity.CardRecord;
import com.longyue.ms.app.service.CardRecordService;
import com.longyue.ms.common.bean.AjaxResult;
import com.longyue.ms.common.bean.Pagination;
import com.longyue.ms.common.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Map;

/**
 * @Auther: Lisp
 * @Date: 2018/7/30 15:19
 * @Description:
 */
@RestController
@RequestMapping("/cardRecord")
public class CardRecordController {

    @Autowired
    private CardRecordService cardRecordService;

    @RequestMapping("/getPageData")
    public Pagination<CardRecord> getPageData(@RequestBody CardRecord cardRecord)throws Exception{
        return cardRecordService.getPagedata(cardRecord);
    }

    @RequestMapping("/insertRecord")
    public AjaxResult insertRecord(String cusName,String cusPhone,String carRecord,
                                   String createTime,String carType,Double maintenanceFees)throws Exception{
        CardRecord cardRecord = new CardRecord();
        cardRecord.setCusName(cusName);
        cardRecord.setCusPhone(cusPhone);
        cardRecord.setCarRecord(carRecord);
        cardRecord.setCreateTime(DateUtils.StrToDate(createTime,"yyyy-MM-dd"));
        cardRecord.setCarType(carType);
        cardRecord.setMaintenanceFees(maintenanceFees);

        return cardRecordService.insertRecord(cardRecord);
    }

    @RequestMapping("/deleteById")
    public AjaxResult deleteById(Long id)throws Exception{
        return cardRecordService.deleteById(id);
    }

    @RequestMapping("/getById")
    public CardRecord getCardRecordById(Long id)throws Exception{
        return cardRecordService.getById(id);
    }

    @RequestMapping("/updateCardRecord")
    public AjaxResult updateSupplier(CardRecord cardRecord)throws Exception{
        return cardRecordService.updateSupplier(cardRecord);
    }

    @RequestMapping("/getTotal")
    @ResponseBody
    public Map<Object,Object> getTotal()throws Exception{
        return cardRecordService.getTotalMenyCount();
    }
}
